This wasn't serving any clear purpose.
'ngl/gsknglshadowlibrary.c',
'ngl/gskngltexturelibrary.c',
'ngl/gskngluniformstate.c',
- 'ngl/gskngltexturepool.c',
+ 'ngl/gskngltexture.c',
'ngl/gskglprofiler.c',
'ngl/stb_rect_pack.c',
'ngl/fp16.c',
#include "gskngliconlibraryprivate.h"
#include "gsknglprogramprivate.h"
#include "gsknglshadowlibraryprivate.h"
-#include "gskngltexturepoolprivate.h"
+#include "gskngltextureprivate.h"
+#include "fp16private.h"
#define ATLAS_SIZE 512
#define MAX_OLD_RATIO 0.5
((GskNglTexture *)data)->user = NULL;
}
+static void
+gsk_ngl_driver_autorelease_texture (GskNglDriver *self,
+ guint texture_id)
+{
+ g_assert (GSK_IS_NGL_DRIVER (self));
+
+ g_array_append_val (self->texture_pool, texture_id);
+}
+
static guint
gsk_ngl_driver_collect_unused_textures (GskNglDriver *self,
gint64 watermark)
g_assert (t->link.next == NULL);
g_assert (t->link.data == t);
- /* Steal this texture and put it back into the pool */
remove_texture_key_for_id (self, t->texture_id);
- gsk_ngl_texture_pool_put (&self->texture_pool, t);
+ gsk_ngl_driver_autorelease_texture (self, t->texture_id);
+ t->texture_id = 0;
+ gsk_ngl_texture_free (t);
}
}
self->autorelease_framebuffers->len = 0;
}
- gsk_ngl_texture_pool_clear (&self->texture_pool);
+ g_clear_pointer (&self->texture_pool, g_array_unref);
g_assert (!self->textures || g_hash_table_size (self->textures) == 0);
g_assert (!self->texture_id_to_key || g_hash_table_size (self->texture_id_to_key) == 0);
g_free,
NULL);
self->shader_cache = g_hash_table_new_full (NULL, NULL, NULL, remove_program);
- gsk_ngl_texture_pool_init (&self->texture_pool);
+ self->texture_pool = g_array_new (FALSE, FALSE, sizeof (guint));
self->render_targets = g_ptr_array_new ();
self->atlases = g_ptr_array_new_with_free_func ((GDestroyNotify)gsk_ngl_texture_atlas_free);
}
GskNglRenderTarget *render_target = g_ptr_array_index (self->render_targets, self->render_targets->len - 1);
gsk_ngl_driver_autorelease_framebuffer (self, render_target->framebuffer_id);
- glDeleteTextures (1, &render_target->texture_id);
+ gsk_ngl_driver_autorelease_texture (self, render_target->texture_id);
g_slice_free (GskNglRenderTarget, render_target);
self->render_targets->len--;
}
/* Release any cached textures we used during the frame */
- gsk_ngl_texture_pool_clear (&self->texture_pool);
+ if (self->texture_pool->len > 0)
+ {
+ glDeleteTextures (self->texture_pool->len,
+ (GLuint *)(gpointer)self->texture_pool->data);
+ self->texture_pool->len = 0;
+ }
/* Reset command queue to our shared queue incase we have operations
* that need to be processed outside of a frame (such as callbacks
int mag_filter)
{
GskNglTexture *texture;
+ guint texture_id;
g_return_val_if_fail (GSK_IS_NGL_DRIVER (self), NULL);
- texture = gsk_ngl_texture_pool_get (&self->texture_pool,
- width, height,
- min_filter, mag_filter);
+ texture_id = gsk_ngl_command_queue_create_texture (self->command_queue,
+ width, height,
+ min_filter, mag_filter);
+ texture = gsk_ngl_texture_new (texture_id,
+ width, height,
+ min_filter, mag_filter,
+ self->current_frame_id);
g_hash_table_insert (self->textures,
GUINT_TO_POINTER (texture->texture_id),
texture);
- texture->last_used_in_frame = self->current_frame_id;
+
return texture;
}
* to free additional VRAM back to the system.
*/
void
-gsk_ngl_driver_release_texture (GskNglDriver *self,
- GskNglTexture *texture)
+gsk_ngl_driver_release_texture (GskNglDriver *self,
+ GskNglTexture *texture)
{
guint texture_id;
g_assert (texture != NULL);
texture_id = texture->texture_id;
+ texture->texture_id = 0;
+ gsk_ngl_texture_free (texture);
if (texture_id > 0)
remove_texture_key_for_id (self, texture_id);
g_hash_table_steal (self->textures, GUINT_TO_POINTER (texture_id));
- gsk_ngl_texture_pool_put (&self->texture_pool, texture);
+ gsk_ngl_driver_autorelease_texture (self, texture_id);
}
/**
#include <gdk/gdkgltextureprivate.h>
#include "gskngltypesprivate.h"
-#include "gskngltexturepoolprivate.h"
+#include "gskngltextureprivate.h"
G_BEGIN_DECLS
GskNglCommandQueue *shared_command_queue;
GskNglCommandQueue *command_queue;
- GskNglTexturePool texture_pool;
-
GskNglGlyphLibrary *glyphs;
GskNglIconLibrary *icons;
GskNglShadowLibrary *shadows;
+ GArray *texture_pool;
GHashTable *textures;
GHashTable *key_to_texture_id;
GHashTable *texture_id_to_key;
--- /dev/null
+/* gskngltexture.c
+ *
+ * Copyright 2020 Christian Hergert <chergert@redhat.com>
+ *
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "config.h"
+
+#include <gdk/gdktextureprivate.h>
+
+#include "gskngltextureprivate.h"
+#include "ninesliceprivate.h"
+
+void
+gsk_ngl_texture_free (GskNglTexture *texture)
+{
+ if (texture != NULL)
+ {
+ g_assert (texture->link.prev == NULL);
+ g_assert (texture->link.next == NULL);
+
+ if (texture->user)
+ g_clear_pointer (&texture->user, gdk_texture_clear_render_data);
+
+ if (texture->texture_id != 0)
+ {
+ glDeleteTextures (1, &texture->texture_id);
+ texture->texture_id = 0;
+ }
+
+ for (guint i = 0; i < texture->n_slices; i++)
+ {
+ glDeleteTextures (1, &texture->slices[i].texture_id);
+ texture->slices[i].texture_id = 0;
+ }
+
+ g_clear_pointer (&texture->slices, g_free);
+ g_clear_pointer (&texture->nine_slice, g_free);
+
+ g_slice_free (GskNglTexture, texture);
+ }
+}
+
+GskNglTexture *
+gsk_ngl_texture_new (guint texture_id,
+ int width,
+ int height,
+ int min_filter,
+ int mag_filter,
+ gint64 frame_id)
+{
+ GskNglTexture *texture;
+
+ texture = g_slice_new0 (GskNglTexture);
+ texture->texture_id = texture_id;
+ texture->link.data = texture;
+ texture->min_filter = min_filter;
+ texture->mag_filter = mag_filter;
+ texture->width = width;
+ texture->height = height;
+ texture->last_used_in_frame = frame_id;
+
+ return texture;
+}
+
+const GskNglTextureNineSlice *
+gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
+ const GskRoundedRect *outline,
+ float extra_pixels_x,
+ float extra_pixels_y)
+{
+ g_assert (texture != NULL);
+ g_assert (outline != NULL);
+
+ if G_UNLIKELY (texture->nine_slice == NULL)
+ {
+ texture->nine_slice = g_new0 (GskNglTextureNineSlice, 9);
+
+ nine_slice_rounded_rect (texture->nine_slice, outline);
+ nine_slice_grow (texture->nine_slice, extra_pixels_x, extra_pixels_y);
+ nine_slice_to_texture_coords (texture->nine_slice, texture->width, texture->height);
+ }
+
+ return texture->nine_slice;
+}
#define __GSK_NGL_TEXTURE_LIBRARY_PRIVATE_H__
#include "gskngltypesprivate.h"
-#include "gskngltexturepoolprivate.h"
+#include "gskngltextureprivate.h"
#include "stb_rect_pack.h"
+++ /dev/null
-/* gskngltexturepool.c
- *
- * Copyright 2020 Christian Hergert <chergert@redhat.com>
- *
- * This file is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This file is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: LGPL-2.1-or-later
- */
-
-#include "config.h"
-
-#include <gdk/gdktextureprivate.h>
-
-#include "gskngltexturepoolprivate.h"
-#include "ninesliceprivate.h"
-
-void
-gsk_ngl_texture_free (GskNglTexture *texture)
-{
- if (texture != NULL)
- {
- g_assert (texture->link.prev == NULL);
- g_assert (texture->link.next == NULL);
-
- if (texture->user)
- g_clear_pointer (&texture->user, gdk_texture_clear_render_data);
-
- if (texture->texture_id != 0)
- {
- glDeleteTextures (1, &texture->texture_id);
- texture->texture_id = 0;
- }
-
- for (guint i = 0; i < texture->n_slices; i++)
- {
- glDeleteTextures (1, &texture->slices[i].texture_id);
- texture->slices[i].texture_id = 0;
- }
-
- g_clear_pointer (&texture->slices, g_free);
- g_clear_pointer (&texture->nine_slice, g_free);
-
- g_slice_free (GskNglTexture, texture);
- }
-}
-
-void
-gsk_ngl_texture_pool_init (GskNglTexturePool *self)
-{
- g_queue_init (&self->queue);
-}
-
-void
-gsk_ngl_texture_pool_clear (GskNglTexturePool *self)
-{
- guint *free_me = NULL;
- guint *texture_ids;
- guint i = 0;
-
- if G_LIKELY (self->queue.length <= 1024)
- texture_ids = g_newa (guint, self->queue.length);
- else
- texture_ids = free_me = g_new (guint, self->queue.length);
-
- while (self->queue.length > 0)
- {
- GskNglTexture *head = g_queue_peek_head (&self->queue);
-
- g_queue_unlink (&self->queue, &head->link);
-
- texture_ids[i++] = head->texture_id;
- head->texture_id = 0;
-
- gsk_ngl_texture_free (head);
- }
-
- g_assert (self->queue.length == 0);
-
- if (i > 0)
- glDeleteTextures (i, texture_ids);
-
- g_free (free_me);
-}
-
-void
-gsk_ngl_texture_pool_put (GskNglTexturePool *self,
- GskNglTexture *texture)
-{
- g_assert (self != NULL);
- g_assert (texture != NULL);
- g_assert (texture->user == NULL);
- g_assert (texture->link.prev == NULL);
- g_assert (texture->link.next == NULL);
- g_assert (texture->link.data == texture);
-
- if (texture->permanent)
- gsk_ngl_texture_free (texture);
- else
- g_queue_push_tail_link (&self->queue, &texture->link);
-}
-
-GskNglTexture *
-gsk_ngl_texture_pool_get (GskNglTexturePool *self,
- int width,
- int height,
- int min_filter,
- int mag_filter)
-{
- GskNglTexture *texture;
-
- g_assert (self != NULL);
-
- texture = g_slice_new0 (GskNglTexture);
- texture->link.data = texture;
- texture->min_filter = min_filter;
- texture->mag_filter = mag_filter;
-
- glGenTextures (1, &texture->texture_id);
-
- glActiveTexture (GL_TEXTURE0);
- glBindTexture (GL_TEXTURE_2D, texture->texture_id);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- else
- glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glBindTexture (GL_TEXTURE_2D, 0);
-
- return texture;
-}
-
-GskNglTexture *
-gsk_ngl_texture_new (guint texture_id,
- int width,
- int height,
- int min_filter,
- int mag_filter,
- gint64 frame_id)
-{
- GskNglTexture *texture;
-
- texture = g_slice_new0 (GskNglTexture);
- texture->texture_id = texture_id;
- texture->link.data = texture;
- texture->min_filter = min_filter;
- texture->mag_filter = mag_filter;
- texture->width = width;
- texture->height = height;
- texture->last_used_in_frame = frame_id;
-
- return texture;
-}
-
-const GskNglTextureNineSlice *
-gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
- const GskRoundedRect *outline,
- float extra_pixels_x,
- float extra_pixels_y)
-{
- g_assert (texture != NULL);
- g_assert (outline != NULL);
-
- if G_UNLIKELY (texture->nine_slice == NULL)
- {
- texture->nine_slice = g_new0 (GskNglTextureNineSlice, 9);
-
- nine_slice_rounded_rect (texture->nine_slice, outline);
- nine_slice_grow (texture->nine_slice, extra_pixels_x, extra_pixels_y);
- nine_slice_to_texture_coords (texture->nine_slice, texture->width, texture->height);
- }
-
- return texture->nine_slice;
-}
+++ /dev/null
-/* gskngltexturepoolprivate.h
- *
- * Copyright 2020 Christian Hergert <chergert@redhat.com>
- *
- * This file is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option)
- * any later version.
- *
- * This file is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: LGPL-2.1-or-later
- */
-
-#ifndef _GSK_NGL_TEXTURE_POOL_PRIVATE_H__
-#define _GSK_NGL_TEXTURE_POOL_PRIVATE_H__
-
-#include "gskngltypesprivate.h"
-
-G_BEGIN_DECLS
-
-typedef struct _GskNglTexturePool
-{
- GQueue queue;
-} GskNglTexturePool;
-
-struct _GskNglTextureSlice
-{
- cairo_rectangle_int_t rect;
- guint texture_id;
-};
-
-struct _GskNglTextureNineSlice
-{
- cairo_rectangle_int_t rect;
- struct {
- float x;
- float y;
- float x2;
- float y2;
- } area;
-};
-
-struct _GskNglTexture
-{
- /* Used to insert into queue */
- GList link;
-
- /* Identifier of the frame that created it */
- gint64 last_used_in_frame;
-
- /* Backpointer to texture (can be cleared asynchronously) */
- GdkTexture *user;
-
- /* Only used by nine-slice textures */
- GskNglTextureNineSlice *nine_slice;
-
- /* Only used by sliced textures */
- GskNglTextureSlice *slices;
- guint n_slices;
-
- /* The actual GL texture identifier in some shared context */
- guint texture_id;
-
- int width;
- int height;
- int min_filter;
- int mag_filter;
-
- /* Set when used by an atlas so we don't drop the texture */
- guint permanent : 1;
-};
-
-void gsk_ngl_texture_pool_init (GskNglTexturePool *self);
-void gsk_ngl_texture_pool_clear (GskNglTexturePool *self);
-GskNglTexture *gsk_ngl_texture_pool_get (GskNglTexturePool *self,
- int width,
- int height,
- int min_filter,
- int mag_filter);
-void gsk_ngl_texture_pool_put (GskNglTexturePool *self,
- GskNglTexture *texture);
-GskNglTexture *gsk_ngl_texture_new (guint texture_id,
- int width,
- int height,
- int min_filter,
- int mag_filter,
- gint64 frame_id);
-const GskNglTextureNineSlice *gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
- const GskRoundedRect *outline,
- float extra_pixels_x,
- float extra_pixels_y);
-void gsk_ngl_texture_free (GskNglTexture *texture);
-
-G_END_DECLS
-
-#endif /* _GSK_NGL_TEXTURE_POOL_PRIVATE_H__ */
--- /dev/null
+/* gskngltextureprivate.h
+ *
+ * Copyright 2020 Christian Hergert <chergert@redhat.com>
+ *
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef _GSK_NGL_TEXTURE_PRIVATE_H__
+#define _GSK_NGL_TEXTURE_PRIVATE_H__
+
+#include "gskngltypesprivate.h"
+
+G_BEGIN_DECLS
+
+struct _GskNglTextureSlice
+{
+ cairo_rectangle_int_t rect;
+ guint texture_id;
+};
+
+struct _GskNglTextureNineSlice
+{
+ cairo_rectangle_int_t rect;
+ struct {
+ float x;
+ float y;
+ float x2;
+ float y2;
+ } area;
+};
+
+struct _GskNglTexture
+{
+ /* Used to insert into queue */
+ GList link;
+
+ /* Identifier of the frame that created it */
+ gint64 last_used_in_frame;
+
+ /* Backpointer to texture (can be cleared asynchronously) */
+ GdkTexture *user;
+
+ /* Only used by nine-slice textures */
+ GskNglTextureNineSlice *nine_slice;
+
+ /* Only used by sliced textures */
+ GskNglTextureSlice *slices;
+ guint n_slices;
+
+ /* The actual GL texture identifier in some shared context */
+ guint texture_id;
+
+ int width;
+ int height;
+ int min_filter;
+ int mag_filter;
+
+ /* Set when used by an atlas so we don't drop the texture */
+ guint permanent : 1;
+};
+
+GskNglTexture *gsk_ngl_texture_new (guint texture_id,
+ int width,
+ int height,
+ int min_filter,
+ int mag_filter,
+ gint64 frame_id);
+const GskNglTextureNineSlice *gsk_ngl_texture_get_nine_slice (GskNglTexture *texture,
+ const GskRoundedRect *outline,
+ float extra_pixels_x,
+ float extra_pixels_y);
+void gsk_ngl_texture_free (GskNglTexture *texture);
+
+G_END_DECLS
+
+#endif /* _GSK_NGL_TEXTURE_PRIVATE_H__ */
#ifndef __NINE_SLICE_PRIVATE_H__
#define __NINE_SLICE_PRIVATE_H__
-#include "gskngltexturepoolprivate.h"
+#include "gskngltextureprivate.h"
#if 0
# define DEBUG_NINE_SLICE